package com.ymttest.utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

import com.ymt.core.tool.FormatUtil;

public class AnalysisDubbo {
	ZooKeeperRetry zoo;

	/**
	 * 连接zookeeper
	 * 
	 * @param zooAddress 172.16.101.22:2181
	 * @throws IOException
	 */
	public AnalysisDubbo(String zooAddress) throws IOException {
//		zoo= new ZooKeeperRetry("172.16.101.22:2181", 5000, null);
		zoo = new ZooKeeperRetry(zooAddress, 5000, new Watcher() {
			@Override
			public void process(WatchedEvent event) {
//		        System.out.println(" receive event : "+event.getType().name());
			}
		});
	}

	/**
	 * 解析facadename对应的app
	 * 
	 * @return
	 * @throws KeeperException
	 * @throws InterruptedException
	 */
//	public Map getAppMap() throws KeeperException, InterruptedException {
//		Map<String, String> getapp = new HashMap<String, String>();
//		zoo.getChildren("/dubbo", false).forEach(x -> {
//			try {
//				zoo.getChildren("/dubbo/" + x, false).forEach(y -> {
//					try {
//						if ("providers".equals(y)) {
//							// 当前系统提供的服务 通过截取facadename 和 application 知道facade是属于哪个站点的
//							zoo.getChildren("/dubbo/" + x + "/" + y, null, null).forEach(provider -> {
//								String url = FormatUtil.urlDecode(provider);
//								url = url.replaceAll("//", "");
//								int start = url.indexOf("/");
//								int param = url.indexOf("?");
//								String facadename = url.substring(start + 1, param);
//								String app = "";
//								try {
//									app = FormatUtil.httpStringToMapSplitAnd(url.substring(param + 1))
//											.get("application").toString();
//								} catch (Exception e) {
//									e.printStackTrace();
//								}
//								getapp.put(facadename, app);
//							});
//						}
//					} catch (KeeperException | InterruptedException e) {
//						e.printStackTrace();
//					}
//				});
//			} catch (KeeperException e) {
//				e.printStackTrace();
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
//		});
//		;
//		return getapp;
//	}
	/**
	 * 获取facadename 前面的部分
	 * @param facadename
	 * @return
	 */
	public String getStartWith(String facadename){
		String appnameStartWith="";
		if(facadename.contains("facade")) {
			appnameStartWith=facadename.substring(0,facadename.indexOf("facade")-1);
		}
		else if(facadename.contains("resource")){
			appnameStartWith=facadename.substring(0,facadename.indexOf("resource")-1);
		}
		else if(facadename.contains("rest")){
			appnameStartWith=facadename.substring(0,facadename.indexOf("rest")-1);
		}
		return appnameStartWith;
	}
	
	/**
	 * 获取全部站点的app-> FacadenameStartWith
	 * @return
	 * @throws KeeperException
	 * @throws InterruptedException
	 */
	public Map getAppFacadenameStartWith() throws KeeperException, InterruptedException {
		Map<String, List<String>> getapp = new HashMap<String, List<String>>();
		zoo.getChildren("/dubbo", false).forEach(x -> {
			try {
				zoo.getChildren("/dubbo/" + x, false).forEach(y -> {
					try {
						if ("providers".equals(y)) {
							// 当前系统提供的服务 通过截取facadename 和 application 知道facade是属于哪个站点的
							//由于application有重复 所以facadename对应的app加上了facadename:的前缀
							zoo.getChildren("/dubbo/" + x + "/" + y, null, null).forEach(provider -> {
								String url = FormatUtil.urlDecode(provider);
								//dubbo://10.96.146.172:20886/com.ymatou.homebiz.facade.BannerFacade?anyhost=true&application=homebiz&dubbo=2.5.7.4&generic=false&interface=com.ymatou.homebiz.facade.BannerFacade&methods=getHomeBanner,getMiniProgramFloatBanner,getBaiduProgramHome,getHomeTimeLimitedSale,getRegUserActivity,getNewComerInfo,getGoodThing,getMiniProgramBannerList,getAppBannerList&pid=39&revision=1.0.9&side=provider&timestamp=1610952087197
								url = url.replaceAll("//", "");
								int start = url.indexOf("/");
								int param = url.indexOf("?");
								String facadename = url.substring(start + 1, param);
//								System.out.println("facadename:"+facadename);
								String appnameStartWith=getStartWith(facadename);
//								if(facadename.contains("facade")) {
//									appnameStartWith=facadename.substring(0,facadename.indexOf("facade")-1);
//								}
//								else if(facadename.contains("resource")){
//									appnameStartWith=facadename.substring(0,facadename.indexOf("resource")-1);
//								}
//								else if(facadename.contains("rest")){
//									appnameStartWith=facadename.substring(0,facadename.indexOf("rest")-1);
//								}
//								System.out.println("appnameStartWith:"+appnameStartWith);
								String app = "";
								try {
									app = FormatUtil.httpStringToMapSplitAnd(url.substring(param + 1))
											.get("application").toString();
								} catch (Exception e) {
									e.printStackTrace();
								}
								if(getapp.get(app)==null||getapp.get(app).isEmpty()) {
									ArrayList<String> arr=new ArrayList<String>();
									arr.add(appnameStartWith);
									getapp.put(app, arr);
								}else {
									if(!getapp.get(app).contains(appnameStartWith)) {
										getapp.get(app).add( appnameStartWith);
									}
								}
							});
						}
					} catch (KeeperException | InterruptedException e) {
						e.printStackTrace();
					}
				});
			} catch (KeeperException e) {
				e.printStackTrace();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
		;
		return getapp;
	}
	
	/**
	 * 解析facadename对应的app
	 * 返回的app重命名
	 * 这里是获取providers 提供者
	 * 
	 * @return
	 * @throws KeeperException
	 * @throws InterruptedException
	 */
	public Map getAppMap2() throws KeeperException, InterruptedException {
		Map<String, String> getapp = new HashMap<String, String>();
		zoo.getChildren("/dubbo", false).forEach(x -> {
			try {
				zoo.getChildren("/dubbo/" + x, false).forEach(y -> {
					try {
						if ("providers".equals(y)) {
							// 当前系统提供的服务 通过截取facadename 和 application 知道facade是属于哪个站点的
							//由于application有重复 所以facadename对应的app加上了facadename:的前缀
							zoo.getChildren("/dubbo/" + x + "/" + y, null, null).forEach(provider -> {
								String url = FormatUtil.urlDecode(provider);
								//dubbo://10.96.146.172:20886/com.ymatou.homebiz.facade.BannerFacade?anyhost=true&application=homebiz&dubbo=2.5.7.4&generic=false&interface=com.ymatou.homebiz.facade.BannerFacade&methods=getHomeBanner,getMiniProgramFloatBanner,getBaiduProgramHome,getHomeTimeLimitedSale,getRegUserActivity,getNewComerInfo,getGoodThing,getMiniProgramBannerList,getAppBannerList&pid=39&revision=1.0.9&side=provider&timestamp=1610952087197
								url = url.replaceAll("//", "");
								int start = url.indexOf("/");
								int param = url.indexOf("?");
								String facadename = url.substring(start + 1, param);
								System.out.println("facadename:"+facadename);
								String appnameStartWith=getStartWith(facadename);
//								if(facadename.contains("facade")) {
//									appnameStartWith=facadename.substring(0,facadename.indexOf("facade")-1);
//								}
//								else if(facadename.contains("resource")){
//									appnameStartWith=facadename.substring(0,facadename.indexOf("resource")-1);
//								}
//								else if(facadename.contains("rest")){
//									appnameStartWith=facadename.substring(0,facadename.indexOf("rest")-1);
//								}
//								System.out.println("appnameStartWith:"+appnameStartWith);
								String app = "";
								try {
									app = FormatUtil.httpStringToMapSplitAnd(url.substring(param + 1))
											.get("application").toString();
								} catch (Exception e) {
									e.printStackTrace();
								}
								getapp.put(facadename, app);
							});
						}
					} catch (KeeperException | InterruptedException e) {
						e.printStackTrace();
					}
				});
			} catch (KeeperException e) {
				e.printStackTrace();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
		;
		return getapp;
	}
	/**
	 * 获取依赖关系
	 * 
	 * @param appMap
	 * @return 服务-依赖的服务列表
	 * @throws KeeperException
	 * @throws InterruptedException
	 */
	public Map<String, List<String>> getConsumer2(Map appMap) throws KeeperException, InterruptedException {
		Map<String, List<String>> getConsumer = new HashMap<String, List<String>>();
		zoo.getChildren("/dubbo", false).forEach(x -> {
			try {
				zoo.getChildren("/dubbo/" + x, false).forEach(y -> {
					try {
						if ("consumers".equals(y)) {
							// 当前系统需要的服务 知道facade需要依赖哪些
							zoo.getChildren("/dubbo/" + x + "/" + y, null, null).forEach(consumer -> {
								//consumer://10.96.169.187/com.ymatou.godmchmanage.facade.ConfigFacade?application=agentproducts.iapi.ymatou.com&category=consumers&check=false&dubbo=2.5.7.6&interface=com.ymatou.godmchmanage.facade.ConfigFacade&methods=getChargeConfig,batchGetBizConfig,setMarketPriceConfig,getBizConfig,getInteractionState,getMchDomesticConfig,getMarketPriceConfig,getBuyerH5Config,getProductPicAutoFillConfig,getConfig,getMchRiskConfig,setChargeConfig,getShareConfigParam,getPromotionWhiteList,getMchMemberExemptConfig,setInteractionState,setBizConfig,getOverseasAddressConfig,setMchAllConfig,getOptionalSettlementCurrency&pid=39&protocol=dubbo&retries=0&revision=3.6.3&side=consumer&timeout=10000&timestamp=1611826673743
								System.out.println(FormatUtil.urlDecode(consumer));
								String url = FormatUtil.urlDecode(consumer);
								url = url.replaceAll("//", "");
								int start = url.indexOf("/");
								int param = url.indexOf("?");
								String facadename = url.substring(start + 1, param);
								String providerApp = "";
								try {
									// 获得提供服务的app名 facadenameStartWith:app
									providerApp = appMap.get(facadename).toString();
								} catch (Exception e) {
								}
								String consumerapp = "";
								try {
									// 获得需要服务的app名
									String application=FormatUtil.httpStringToMapSplitAnd(url.substring(param + 1))
											.get("application").toString();
									String appnameStartWith=getStartWith(facadename);
									consumerapp = application;
									String check = (String) FormatUtil.httpStringToMapSplitAnd(url.substring(param + 1))
											.get("check").toString();
									if (!"false".equals(check)) {
										System.out.println("check:" + consumerapp + ":强依赖:" + providerApp);
									}
								} catch (Exception e) {
									e.printStackTrace();
								}
								System.out.println("providerApp"+":"+providerApp+":consumerapp:"+consumerapp);
								if (!"".equals(providerApp) && !providerApp.equals(consumerapp)) {
									if (getConsumer.get(consumerapp) == null) {
										ArrayList<String> list = new ArrayList<String>();
										list.add(providerApp);
										getConsumer.put(consumerapp, list);
									} else {
										if (!getConsumer.get(consumerapp).contains(providerApp)) {
											getConsumer.get(consumerapp).add(providerApp);
										}
//										getConsumer.put(consumerapp,Arrays.asList(providerApp));
									}
								}
							});
						}
					} catch (KeeperException | InterruptedException e) {
						e.printStackTrace();
					}
				});
			} catch (KeeperException e) {
				e.printStackTrace();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
		;
		return getConsumer;
	}
//	/**
//	 * 获取依赖关系
//	 * 用于处理getappmap
//	 * @param appMap
//	 * @return 服务-依赖的服务列表
//	 * @throws KeeperException
//	 * @throws InterruptedException
//	 */
//	public Map<String, List<String>> getConsumer2(Map appMap) throws KeeperException, InterruptedException {
//		Map<String, List<String>> getConsumer = new HashMap<String, List<String>>();
//		zoo.getChildren("/dubbo", false).forEach(x -> {
//			try {
//				zoo.getChildren("/dubbo/" + x, false).forEach(y -> {
//					try {
//						if ("consumers".equals(y)) {
//							// 当前系统需要的服务 知道facade需要依赖哪些
//							zoo.getChildren("/dubbo/" + x + "/" + y, null, null).forEach(consumer -> {
//								//consumer://10.96.169.187/com.ymatou.godmchmanage.facade.ConfigFacade?application=agentproducts.iapi.ymatou.com&category=consumers&check=false&dubbo=2.5.7.6&interface=com.ymatou.godmchmanage.facade.ConfigFacade&methods=getChargeConfig,batchGetBizConfig,setMarketPriceConfig,getBizConfig,getInteractionState,getMchDomesticConfig,getMarketPriceConfig,getBuyerH5Config,getProductPicAutoFillConfig,getConfig,getMchRiskConfig,setChargeConfig,getShareConfigParam,getPromotionWhiteList,getMchMemberExemptConfig,setInteractionState,setBizConfig,getOverseasAddressConfig,setMchAllConfig,getOptionalSettlementCurrency&pid=39&protocol=dubbo&retries=0&revision=3.6.3&side=consumer&timeout=10000&timestamp=1611826673743
//								System.out.println(FormatUtil.urlDecode(consumer));
//								String url = FormatUtil.urlDecode(consumer);
//								url = url.replaceAll("//", "");
//								int start = url.indexOf("/");
//								int param = url.indexOf("?");
//								String facadename = url.substring(start + 1, param);
//								String providerApp = "";
//								try {
//									// 获得提供服务的app名
//									providerApp = appMap.get(facadename).toString();
//								} catch (Exception e) {
//								}
//								String consumerapp = "";
//								try {
//									// 获得需要服务的app名
//									consumerapp = FormatUtil.httpStringToMapSplitAnd(url.substring(param + 1))
//											.get("application").toString();
//									String check = (String) FormatUtil.httpStringToMapSplitAnd(url.substring(param + 1))
//											.get("check").toString();
//									if (!"false".equals(check)) {
//										System.out.println("check:" + consumerapp + ":强依赖:" + providerApp);
//									}
//								} catch (Exception e) {
//									e.printStackTrace();
//								}
//								if (!"".equals(providerApp) && !providerApp.equals(consumerapp)) {
//									if (getConsumer.get(consumerapp) == null) {
//										ArrayList<String> list = new ArrayList<String>();
//										list.add(providerApp);
//										getConsumer.put(consumerapp, list);
//									} else {
//										if (!getConsumer.get(consumerapp).contains(providerApp)) {
//											getConsumer.get(consumerapp).add(providerApp);
//										}
////										getConsumer.put(consumerapp,Arrays.asList(providerApp));
//									}
//								}
//							});
//						}
//					} catch (KeeperException | InterruptedException e) {
//						e.printStackTrace();
//					}
//				});
//			} catch (KeeperException e) {
//				e.printStackTrace();
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
//		});
//		;
//		return getConsumer;
//	}
	/**
	 * 返回没依赖的站点列表
	 * 
	 * @param dependent2 站点列表
	 * @param Analysis1  k 站点 v 依赖列表
	 * @return
	 */
	public static ArrayList<String> getDependent(ArrayList<String> dependent2, Map<String, List<String>> Analysis1) {
		ArrayList<String> dependent3 = new ArrayList<String>();
		for (int i = 0; i < dependent2.size(); i++) {
			if (Analysis1.get(dependent2.get(i)) == null || Analysis1.get(dependent2.get(i)).size() == 0) {
				dependent3.add(dependent2.get(i));
			}
		}
		dependent3 = (ArrayList) dependent3.stream().distinct().sorted().collect(Collectors.toList());
		return dependent3;
	}

	/**
	 * 移除依赖 Analysis1 v 中包含 publish1 的部分移除
	 * 
	 * @param Analysis1 k v
	 * @param publish1
	 * 
	 */
	public static void removeAnalysis(Map<String, List<String>> Analysis1, ArrayList publish1) {
		// 移除依赖
		Analysis1.forEach((k, v) -> {
			if (v != null) {
				publish1.forEach(x -> {
					v.remove(x);
				});
			}
		});
	}

	/**
	 * 获取下一级别发布
	 * 
	 * @param Analysis1  当前的分析结果
	 * @param publish2   所有已发布移除的站点列表
	 * @param alldomain2 所有站点列表
	 * @return
	 */
	public static ArrayList getNextPublish(Map<String, List<String>> Analysis1, ArrayList publish2,
			ArrayList<String> alldomain2) {
		// 所有已经移除的站点列表从结果集中移除
		removeAnalysis(Analysis1, publish2);
		ArrayList publish3 = getDependent(alldomain2, Analysis1);
		// 所有没有依赖的-上一次全部移除的=本次新增移除
		publish3.removeAll(publish2);
//		System.out.println("publish3:"+publish3);
		return publish3;
	}

	/**
	 * 移除重复引用
	 * 
	 * @param analysis1
	 */
	private List<String> removeRepeat(Map<String, List<String>> analysis1) {
		List<String> repeatlist=new ArrayList<String>();
		analysis1.forEach((k, v) -> {
			Iterator<String> iterator = v.iterator();
			while (iterator.hasNext()) {
				String v1 = iterator.next();
				if (analysis1.get(v1) != null && analysis1.get(v1).contains(k)) {
					System.out.println("重复引用:" + k + ":" + v1);
					repeatlist.add(k);
					repeatlist.add(v1);
					iterator.remove();// 使用迭代器的删除方法删除
					analysis1.get(v1).remove(k);
				}
			}
		});
		return repeatlist.stream().distinct().collect(Collectors.toList());
	}

	/**
	 * 移除指定重复引用
	 * 
	 * @param analysis1
	 */
	private void removeRepeat(Map<String, List<String>> analysis1, String servername) {
		analysis1.forEach((k, v) -> {
			Iterator<String> iterator = v.iterator();
			while (iterator.hasNext()) {
				String v1 = iterator.next();
				if (analysis1.get(v1) != null && analysis1.get(v1).contains(servername)) {
//					System.out.println("移除指定引用:" + k + ":" + servername);
					iterator.remove();// 使用迭代器的删除方法删除
				}
			}
		});

	}

	/**
	 * 发现三级重复引用
	 * 
	 * @param analysis1
	 */
	private ArrayList<String> findThirdRepeat(Map<String, List<String>> analysis1) {
		ArrayList<String> tr = new ArrayList<String>();
		analysis1.forEach((k, v) -> {
			Iterator<String> iterator = v.iterator();
			while (iterator.hasNext()) {
				String v1 = iterator.next();
				Iterator<String> iterator2 = analysis1.get(v1).iterator();
				while (iterator2.hasNext()) {
					String v2 = iterator2.next();
					if (analysis1.get(v2) != null && analysis1.get(v2).contains(k)) {
						System.out.println("3级重复引用:" + k + ":" + v1 + ":" + v2);
						tr.add(v2);
					}
				}
			}
		});
		return tr;
	}

	/**
	 * 发现4级重复引用
	 * 
	 * @param analysis1
	 * @return
	 */
	private ArrayList<String> findFourRepeat(Map<String, List<String>> analysis1) {
		ArrayList<String> fr = new ArrayList<String>();
		analysis1.forEach((k, v) -> {
			Iterator<String> iterator = v.iterator();
			while (iterator.hasNext()) {
				String v1 = iterator.next();
				Iterator<String> iterator2 = analysis1.get(v1).iterator();
				while (iterator2.hasNext()) {
					String v2 = iterator2.next();

					Iterator<String> iterator3 = analysis1.get(v2).iterator();
					while (iterator3.hasNext()) {
						String v3 = iterator3.next();

						if (analysis1.get(v3) != null && analysis1.get(v3).contains(k)) {
							System.out.println("4级重复引用:" + k + ":" + v1 + ":" + v2 + ":" + v3);
							fr.add(v3);
						}
					}

				}
			}
		});
		return fr;

	}
	public static void main(String args[]) throws IOException, KeeperException, InterruptedException {
		AnalysisDubbo AnalysisDubbo = new AnalysisDubbo("172.16.101.22:2181");
		System.out.println(AnalysisDubbo.getAppMap2());
		// a站点依赖b,c,d站点
		Map<String, List<String>> Analysis1 = AnalysisDubbo.getConsumer2(AnalysisDubbo.getAppMap2());
		System.out.println("Analysis:" + Analysis1);
//		System.exit(0);
		// 移除重复引用(a b 互相引用)
		List<String> repeatlist = AnalysisDubbo.removeRepeat(Analysis1);
		// 获取全部被依赖的站点列表 排重
		ArrayList<String> alldomain = new ArrayList<String>();
		Analysis1.forEach((k, v) -> {
			alldomain.add(k);
			alldomain.addAll(v);
		});
		ArrayList alldomain2 = (ArrayList) alldomain.stream().distinct().sorted().collect(Collectors.toList());
		System.out.println("alldomain:" + alldomain2);
		// 本次发布的站点
		ArrayList<String> publish = new ArrayList<String>();
		// 所有发布过的站点 移除
		ArrayList allremove = new ArrayList<String>();
		int i = 1;
		while (true) {
			// 获取本级别需要发布的站点列表
			publish = AnalysisDubbo.getNextPublish(Analysis1, allremove, alldomain2);
			// 加入所有移除
			allremove.addAll(publish);
			allremove = (ArrayList) allremove.stream().distinct().collect(Collectors.toList());
			System.out.println("publish" + i + ":" + publish);
			// 出现当前没有发布的情况 可能是重复引用死循环
			if (publish == null || publish.size() == 0) {
				// 获取重复引用站点列表(3级+4级) a-b-c-d-a
				ArrayList<String> fr = AnalysisDubbo.findFourRepeat(Analysis1);
				ArrayList<String> tr = AnalysisDubbo.findThirdRepeat(Analysis1);
				fr.addAll(tr);
				fr = (ArrayList<String>) fr.stream().distinct().collect(Collectors.toList());
				//这里获取到2 3 4级全部的重复列表
				repeatlist.addAll(fr);
				repeatlist=(ArrayList<String>) repeatlist.stream().distinct().collect(Collectors.toList());
				System.out.println("循环引用站点列表:" + fr);
				fr.forEach(x -> {
					AnalysisDubbo.removeRepeat(Analysis1, x);
				});
				;
				i++;
				// 次数过多跳出
				if (i > 20) {
					break;
				}
				continue;
			}
			// 次数过多跳出
			if (i > 20) {
				break;
			}
			i++;
		}
		System.out.println("Analysis:" + Analysis1);
		System.out.println("repeatlist"+repeatlist);
		Map appF = AnalysisDubbo.getAppFacadenameStartWith();
		repeatlist.forEach(x->{
			System.out.println(x+":"+appF.get(x));
		});
	}
	//以前的分析 保留
//	public static void main2(String args[]) throws IOException, KeeperException, InterruptedException {
//		AnalysisDubbo AnalysisDubbo = new AnalysisDubbo("172.16.101.22:2181");
//		System.out.println(AnalysisDubbo.getAppMap());
//		System.exit(0);
//		// a站点依赖b,c,d站点
//		Map<String, List<String>> Analysis1 = AnalysisDubbo.getConsumer(AnalysisDubbo.getAppMap());
//		System.out.println("Analysis:" + Analysis1);
//		// 移除重复引用(a b 互相引用)
//		AnalysisDubbo.removeRepeat(Analysis1);
//		// 获取全部被依赖的站点列表 排重
//		ArrayList<String> alldomain = new ArrayList<String>();
//		Analysis1.forEach((k, v) -> {
//			alldomain.add(k);
//			alldomain.addAll(v);
//		});
//		ArrayList alldomain2 = (ArrayList) alldomain.stream().distinct().sorted().collect(Collectors.toList());
//		System.out.println("alldomain:" + alldomain2);
//		// 本次发布的站点
//		ArrayList<String> publish = new ArrayList<String>();
//		// 所有发布过的站点 移除
//		ArrayList allremove = new ArrayList<String>();
//		int i = 1;
//		while (true) {
//			// 获取本级别需要发布的站点列表
//			publish = AnalysisDubbo.getNextPublish(Analysis1, allremove, alldomain2);
//			// 加入所有移除
//			allremove.addAll(publish);
//			allremove = (ArrayList) allremove.stream().distinct().collect(Collectors.toList());
//			System.out.println("publish" + i + ":" + publish);
//			// 出现当前没有发布的情况 可能是重复引用死循环
//			if (publish == null || publish.size() == 0) {
//				// 获取重复引用站点列表(3级+4级) a-b-c-d-a
//				ArrayList<String> fr = AnalysisDubbo.findFourRepeat(Analysis1);
//				ArrayList<String> tr = AnalysisDubbo.findThirdRepeat(Analysis1);
//				fr.addAll(tr);
//				fr = (ArrayList<String>) fr.stream().distinct().collect(Collectors.toList());
//				System.out.println("循环引用站点列表:" + fr);
//				fr.forEach(x -> {
//					AnalysisDubbo.removeRepeat(Analysis1, x);
//				});
//				;
//				i++;
//				// 次数过多跳出
//				if (i > 20) {
//					break;
//				}
//				continue;
//			}
//			// 次数过多跳出
//			if (i > 20) {
//				break;
//			}
//			i++;
//		}
//		System.out.println("Analysis:" + Analysis1);
//	}

}
